package com.dianganjiao.lib.adapter

import android.text.TextUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.dianganjiao.lib.R
import com.dianganjiao.lib.util.DPUtil
import com.dianganjiao.lib.util.ImgLoader
import com.dianganjiao.lib.util.Screen

/**
 * create file time : 2021/3/19
 * create user : wxl
 * subscribe :
 */
class GridImageAdapter : BaseQuickAdapter<String, BaseViewHolder>{

    private var margin = 0

    constructor(data: MutableList<String>?) : super(R.layout.item_grid_image_layoout,data)

    fun setMargin(m:Int){
        this.margin = m
    }

    override fun convert(helper: BaseViewHolder, item: String) {
        Screen.splitWidthHeightEquals(helper.itemView,3,margin+ DPUtil.px2dip(6))
        if(!TextUtils.equals("space",item)){
            helper.setGone(R.id.gridImageItemEmptyLayout,true)
            helper.setGone(R.id.gridImageItemImg,false)
            if(item.startsWith("http")){
                ImgLoader.loadCorner(helper.getView(R.id.gridImageItemImg), item, 5f)
            } else {
                ImgLoader.loadCornerFile(helper.getView(R.id.gridImageItemImg), item, 5f)
            }
        } else {
            helper.setGone(R.id.gridImageItemEmptyLayout,false)
            helper.setGone(R.id.gridImageItemImg, true)
        }
    }

    fun setData(d:MutableList<String>){
        data.clear()
        data.addAll(d)
        notifyDataSetChanged()
    }

}